package com.example.administrator.yuejian_2.adapter;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.bean.ActivityCollectBean;
import com.example.administrator.yuejian_2.viewholder.ActivityCollectListViewHolder;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/10.
 */

public class ActivityCollectListAdapter extends RecyclerView.Adapter {


    private List<ActivityCollectBean> activity = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;
    private int aid,uid;

    public ActivityCollectListAdapter(Context context, List<ActivityCollectBean> activity){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.activity.addAll(activity);
        SharedPreferences sharedPreferences = context.getSharedPreferences("userInfo",
                Context.MODE_PRIVATE);
        uid = sharedPreferences.getInt("user_id",0);

    }




    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_activitycollect,parent,false);
        ActivityCollectListViewHolder holder = new ActivityCollectListViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ActivityCollectListViewHolder activityholder = (ActivityCollectListViewHolder) holder;
        ActivityCollectBean activitylist = activity.get(position);
        activityholder.activityname.setText(activitylist.getA_name());
        String activity_picture = activitylist.getA_pic();
        if (!activity_picture.equals(""))
            Picasso.with(context).
                    load("http://10.0.2.2/yuejian16/Public/clubphoto/"+activity_picture)
                    .into(activityholder.activitypic);

        final int aid = activitylist.getAid();
//        activityholder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent = new Intent(context, AcDetailActivity.class);
//                intent.putExtra("aid",aid);
//                context.startActivity(intent);
//
//            }
//        });


    }

    @Override
    public int getItemCount() {

        return activity.size();
    }
}




